﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using Newtonsoft.Json;
using ZX.BPM.Library;
using ZX.EHR.Library;
namespace ZX.WebApp.Mobi.proc
{
    /// <summary>
    /// GetData 的摘要说明
    /// </summary>
    public class GetData : IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {
        DatUser user = new DatUser();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string type = context.Request["TYPE"];
            string para = context.Request["PARA"];
            if (HttpContext.Current.Session["User"] != null ){
                user = (DatUser)HttpContext.Current.Session["User"];
                context.Response.Write(Proc(type, para));
            }
            //else if (type == "GetUser1"){//yonghuyanzheng
            //    context.Response.Write(GetUser(para));
            //}
            else{
                context.Response.Write("@@N*L@@");
            }
        }
        private string Proc(string type, string para)
        {
            string back = "";
            switch (type)
            {
                //case "GetTaskCount":
                //    back = GetTaskCount();
                //    break;
                case "UnLoad":
                    back = UnLoad();
                    break;
                //case "GetTask":
                //    back = GetTask(para);
                //    break;
                case "LoadDeptTree":
                    back = (new ZX.Web.UI.Controls.TreeView()).createTreeHtml("@001-001");
                    break;
                //case "GetUser":
                //    back = GetUser(para);
                //    break;
            }
            return back;
        }
        //获取待办总数
        //private string GetTaskCount()
        //{
        //    return (new BHF_TaskInstanceView()).GetTaskInstanceCount("", "", user.LoginName, 0, 20).ToString();
        //}

        //获取待办
        //private string GetTask(string para)
        //{
        //    string[] p = para.Split('︾');
        //    string selectname = "";
        //    int firs = Convert.ToInt32(p[0]);
        //    int size = Convert.ToInt32(p[1]);
        //    if (p.Length > 2)
        //    {
        //         selectname = p[2].ToString();
        //    }
        //    return JsonConvert.SerializeObject((new BHF_TaskInstanceView()).GetTaskDatatable("", selectname, user.LoginName, firs, size));
        //}
        /// <summary>
        /// 根据部门Or姓名 获取人员
        /// </summary>
        /// <param name="deptid"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        //private string GetUser(string value)
        //{
        //    string[] p = value.Split(',');
        //    string deptid = p[0].ToString();
        //    string name=null;
        //    if (p.Length > 1)
        //    {
        //        name = p[1].ToString();
        //    }
        //    return JsonConvert.SerializeObject((new BHF_TaskInstanceView()).GetDatUser(deptid, name));
        //}


        public string GetWorkFlowList(string UserID)
        {
            return "";
        }



        private string UnLoad()
        {
            try
            {
                FormsAuthentication.SignOut();
                HttpContext.Current.Session["User"] = null;
                HttpContext.Current.Session["IsOutSite"] = null;
                HttpContext.Current.Session["vcode"] = null;
                return "1";
            }
            catch (Exception)
            {
                return "0";
            }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }


    }
}